; 在多个 GUI 窗口中使用

#Include MouseEvent.ahk


g := Gui('+AlwaysOnTop')
g.SetFont('s18', 'consolas')
g.MarginX := g.MarginY := 10
me := MouseEvent(g.Hwnd)

wheelTest := g.AddText('x10 w390 Center h30 Backgroundc19423', 1)
me.RegisterOnCondition(MouseEvent.Events.MOUSE_WHEEL,
  (point, *) => inEl(point.ConvertToClient(g), wheelTest),
  (_, up, *) => wheelTest.Text += up ? 1 : -1)

; === 子窗口
sub := Gui('+AlwaysOnTop -Caption +ToolWindow +Border +Parent' g.Hwnd)
sub.SetFont('s18', 'consolas')
sub.MarginX := g.MarginY := 10
me1 := MouseEvent(sub.Hwnd)


wheelTest1 := sub.AddText('x10 w300 Center h30 Backgroundc19423', 1)
me1.RegisterOnCondition(MouseEvent.Events.MOUSE_WHEEL,
  (point, *) => inBox(point.ConvertToClient(g), 110, 120, 300, 30),
  (_, up, *) => wheelTest1.Text += up ? 1 : -1)

DllCall('SetParent', 'ptr', sub.Hwnd, 'ptr', g.Hwnd)

g.Show('w600 h600')
sub.Show('x100 y100 w400 h400')

; ===
inBox(pos, x, y, w, h) {
  return pos.x >= x && pos.x <= x + w
    && pos.y >= y && pos.y <= y + h
}

inEl(pos, el) {
  el.GetPos(&x, &y, &w, &h)
  return inBox(pos, x, y, w, h)
}